package com.manes.agents;

import jade.core.AID;
import jade.core.Agent;
import jade.core.AgentContainer;
import jade.core.behaviours.CyclicBehaviour;
import jade.lang.acl.ACLMessage;
import jade.util.leap.Iterator;
import jade.wrapper.AgentController;
import jade.wrapper.PlatformController;

public class solverAgent extends Agent{
	protected void setup(){
		//printout a welcome message
		
		//System.out.println("My local-name is "+getAID().getLocalName());
		//System.out.println("My GUID is"+getAID().getName());
		
		//String msg = new String("solver Agent " + getName()+" has been created.");
		
		ACLMessage msgSend = new ACLMessage(ACLMessage.INFORM);
		msgSend.addReceiver(new AID("Manes", AID.ISLOCALNAME));
		
		msgSend.setLanguage("English");
		msgSend.setOntology("mnsOnto");
		msgSend.setContent("Clone created");
		send(msgSend);
		
		addBehaviour(new CyclicBehaviour(this) {
			public void action() {
				ACLMessage msg = myAgent.receive();
				if (msg != null) {
					createSolver();
				} else {
					block();
				}
			}
		});
	}
	public void createSolver(){
		String name = "solverAgentClone";
		PlatformController c = getContainerController();
		try{
			AgentController a =  c.createNewAgent(name,"com.manes.agents.solverAgent",null);
			a.start();
		}
		catch (Exception e){}
	}
	
}
